<template>
  <div class="address">
      <!-- 顶部导航 -->
      <van-nav-bar fixed
      title="我的收货地址"
      left-text="返回"
      right-text="新增地址"
      left-arrow
      @click-left="$router.go(-1)"
      @click-right="toAdd"
    />

    <ul class="address">
        <li v-for="(item,index) in addresslist" :key="index">
            <div class="address">
                <p class="p1">{{item.address}}</p>
                <span class="p2">{{item.name}}</span>
                <span class="p3">{{item.phone}}</span>

            </div>
            <van-icon name="chat-o"  class="icon" @click="handClick(index)"/>
            
        </li>
    </ul>
  </div>
  
    
  
</template>

<script>
import { mapState } from 'vuex';
import eventbus from '../utils/tools';
export default {
    data(){
        return{
            currentIndex:0
        }
    },
    computed:{
    ...mapState(['addresslist']),
    },
    mounted(){
    //    console.log(this.addresslist);
    },
    methods:{
        // ...mapMutations(['request_addresslist']),
        toAdd(){
            this.$router.push('/addAddress')
        },
  
  handClick(index){
    eventbus.$emit('deliverIndex',index);//触发事件并传值
    this.currentIndex = index;
    this.$router.push('/edit');
    console.log(index);
    // console.log(this.addresslist[index]);
  }
       
    }
}
</script>

<style lang="scss" scoped>
    ul{
        width: 100%;
        margin-top: 40px;
    }
    ul li{
        height: 60px;
        width: 100%;
        display: flex;
        justify-content: space-between;
        padding: 10px 0;
        border-bottom: 1px solid #f5f5f5;
    }
    .address .p1{
        font-size: 18px;
        font-weight: bold;
        margin: 5px 10px;
    }
    .p2{
        font-size: 14px;
        color: gray;
        margin: 0 5px 0 10px;
    }
    .p3{
        font-size: 14px;
        color: gray;
    }
    .icon{
        font-size: 20px;
        margin-top: 20px;
        margin-right: 10px;
    }


</style>